# -*- coding:utf-8 -*-
# !/usr/bin/python
# 该脚本用于更新单平台后端large或less的全区服 python fs_update_all_python_mult_V.large_less.py 平台名 large或less 区服

import sys
reload(sys)												 # reload 才能调用 setdefaultencoding 方法
sys.setdefaultencoding('utf-8')	 # 设置 'utf-8'
from multiprocessing import Process, Pool, Queue, Manager
import os
import MySQLdb
import time
import paramiko
import logging
import sys
import socket


def run_proc(ip):  # 定义一个函数用于进程调用

    print ip
    #comm = qu.split(":")[1]


    print 'Run child process %s' % (os.getpid())
    logging.debug(" %s start Update " % ip)
    time.sleep(0.2)
    logging.debug("################################")
    logging.getLogger("paramiko").setLevel(logging.WARNING)
    sshport = 22
    username = "root"
    pkey = '/root/.ssh/id_rsa'
    key = paramiko.RSAKey.from_private_key_file(pkey)
    # 正式使用时，要检查这里的 svn up
    command = 'free -m;'
    s = paramiko.SSHClient()
    s.load_system_host_keys()
    s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    s.connect(ip, sshport, username, pkey=key)
    stdin, stdout, sterr = s.exec_command(command)
    a = stdout.read()
    #print a
    a = a + sterr.read()
    print a
    logging.debug(str(a).replace("\n", ""))
    logging.debug(" %s Update Done" % ip)
    logging.debug("################################")
    s.close()

run_proc('02tw.fs.pthc1.com')